import java.util.*;

/**
 * Die Klasse <code>Task</code> implementiert einen Task.
 * 
 * @author anon
 * @version 29.01
 * 
 */

// ############################## Datenfelder ##############################

public class Task extends ProjectItem {
		
	public List<ProjectItem> projectItem;

// ############################## Konstruktoren ##############################

	public Task(String name, String details, double rate) {
		super(name, details, rate);
		projectItem = new LinkedList<ProjectItem>();
	}
	
// ############################## Methoden ##############################
	
	public void addProjectItem(ProjectItem pi) {
		projectItem.add(pi);
	}
	
	public void removeProjectItem(ProjectItem pi) {
		projectItem.remove(pi);
		projectItem.remove(pi);
	}
	
	/*public Set<Deliverable> allDeliverables() {
		Set<Deliverable> deliverables = new HashSet<Deliverable>();
		
		for(ProjectItem pi : projectItem) {
			
			if(pi.getClass().getName() == "Deliverable")
				deliverables.add((Deliverable) pi);
			
			if(pi.getClass().getName() == "Task")
				deliverables.addAll(pi.allDeliverables());
		}		
		return deliverables;
	}*/
	
	public double getTimeRequired() {
		double totaltime = 0.0;
		for(ProjectItem tmp : projectItem) {
			totaltime = totaltime + tmp.getTimeRequired();
		}
		return totaltime;
	}
	
	public double getMaterialsCost() {
		double materialCost = 0.0;
		for(ProjectItem tmp : projectItem) {
			materialCost = materialCost + tmp.getMaterialsCost();
		}
		return materialCost;
	}
	
	public Set<Deliverable> allDeliverables(){
		Set<Deliverable> deliverables=new TreeSet<Deliverable>();
			for(ProjectItem item: projectItem){
				if (item instanceof Deliverable)deliverables.add((Deliverable)item);
				else deliverables.add(((Deliverable)item.allDeliverables())); 
				}
			return deliverables;
	}
	
}


